#!/usr/bin/env python

import wx

class Presenter(object):
    """Presenter base class"""
    
    def __init__(self, view, interactor):
        self.view = view
        self.interactor = interactor
        self.interactor.install(self.view, self)
    
    def restoreSize(self, config):
        name = self.view.Name
        width = config.ReadInt('%s/Width' % name, -1)
        height = config.ReadInt('%s/Height' % name, -1)
        if width != -1 and height != -1:
            self.view.Size = wx.Size(width, height)
    
    def restorePosition(self, config):
        name = self.view.Name
        x = config.ReadInt('%s/X' % name, -1)
        y = config.ReadInt('%s/Y' % name, -1)
        if x == -1 or y == -1: self.view.CenterOnScreen()
        else: self.view.Position = wx.Point(x, y)
    
    def restoreMaximized(self, config):
        name = self.view.Name
        maximized = config.ReadInt('%s/Maximized' % name, 0)
        if maximized: self.view.Maximize()
    
    def saveSize(self, config):
        if self.view.IsMaximized() or self.view.IsIconized(): return
        
        name = self.view.Name
        config.WriteInt('%s/X' % name, self.view.Position.x)
        config.WriteInt('%s/Y' % name, self.view.Position.y)
    
    def savePosition(self, config):
        if self.view.IsMaximized() or self.view.IsIconized(): return
        
        name = self.view.Name
        config.WriteInt('%s/Width' % name, self.view.Size.width)
        config.WriteInt('%s/Height' % name, self.view.Size.height)
    
    def saveMaximized(self, config):
        name = self.view.Name
        maximized = 1 if self.view.IsMaximized() else 0
        config.WriteInt('%s/Maximized' % name, maximized)
        
    def activate(self, active):
        """Called when frame activated"""
        
        if active:
            self.view.SetTransparent(250)
        else:
            self.view.SetTransparent(250)
    
    def close(self):
        pass
    